package org.mch.comm.lang;

import java.io.Serializable;

/**
 * 描述：；<BR/>
 * 
 * @author ZL；<BR/>
 *
 *         参考：MCHWEB.NET；<BR/>
 *
 */
public class MBoolean implements Serializable, Comparable<Object> {
	private static final long serialVersionUID = 238995173496905287L;

	private String value = "N";

	public MBoolean(char ch) {
		super();
		value = ch == 'Y' || ch == 'y' ? "Y" : "N";
	}

	public MBoolean(String val) {
		if ("true".equalsIgnoreCase(val) || "Y".equalsIgnoreCase(val))
			value = "Y";
		else
			value = "N";
	}

	public MBoolean(boolean b) {
		super();
		value = b ? "Y" : "N";
	}

	public boolean booleanValue() {
		return value.equalsIgnoreCase("Y") ? true : false;
	}

	public static MBoolean valueOf(boolean b) {
		return (b ? new MBoolean(true) : new MBoolean(false));
	}

	public static MBoolean valueOf(String val) {
		if ("true".equalsIgnoreCase(val) || "Y".equalsIgnoreCase(val))
			return new MBoolean(true);
		else
			return new MBoolean(false);
	}

	public boolean equals(Object obj) {
		if ((obj != null) && (obj instanceof MBoolean)) {
			return booleanValue() == ((MBoolean) obj).booleanValue();
		}
		return false;
	}

	public int hashCode() {
		return value == "Y" || value == "Y" ? 1231 : 1237;
	}

	public String toString() {
		return value;
	}

	public int compareTo(Object o) {
		if (o == null)
			return 1;
		return toString().compareTo(o.toString());
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public void setValue(boolean value) {
		this.value = value ? "Y" : "N";
	}
}